// banner轮播图
function slideshow() {
    $('.banContent span').on('mouseover', function() {
        // console.log($(this));
        var index = $(this).attr('data-page')
        console.log(index);

        if (index == 1) {
            $(this).addClass('page_active').siblings().removeClass('page_active')
            $(this).parent().siblings().children().attr('src', './image/wmq/banner01.jpg')
            $(this).parent().parent().parent().parent().css('backgroundColor', 'rgb(226, 239, 209)')
        } else if (index == 2) {
            $(this).addClass('page_active').siblings().removeClass('page_active')
            $(this).parent().siblings().children().attr('src', './image/wmq/banner02.jpg')
            $(this).parent().parent().parent().parent().css('backgroundColor', 'rgb(192, 223, 251)')
        }
    })
}

// 初始化
function dogInit(type, floor, showResult, el) {
    $.ajax({
        type: 'get',
        url: 'http://localhost:3000/dog/getRecommend',
        data: {
            type,
            floor
        },
        dataType: 'json',
        success: function(data) {
            // console.log(data);
            showResult[type] = data.data
            var html = ''
            if (data.code) {
                data.data.forEach((item) => {
                    html += `<dl class="first">
                    <dt>
                            <a href="javascript:;">
                                <img src="${item.image}" alt="">
                            </a>
                        </dt>
                    <dd>
                        <a href="javascript:;">${item.title}</a>
                    </dd>
                    <dd>
                        <span class="l">¥ ${item.price}</span>
                        <span class="r">已售${item.sales}</span>
                    </dd>
                </dl>`
                })
                $(el).html(html)
            }
        }
    })
}

function dogGet(type, floor, showResult, overEl, htmlEl, actEl) {
    $(overEl).on('mouseover', function() {
        if (actEl == 'active1') {
            $(this).addClass(actEl).siblings().removeClass(actEl)
        } else if (actEl == 'current') {
            $(this).addClass(actEl).parent().siblings().children().removeClass(actEl)
        }

        type = $(this).attr('data-type')
            // console.log(type);
        if (showResult[type]) {
            var html = ''
            showResult[type].forEach((item) => {
                html += `<dl class="first">
                            <dt>
                                    <a href="javascript:;">
                                        <img src="${item.image}" alt="">
                                    </a>
                                </dt>
                            <dd>
                                <a href="javascript:;">${item.title}</a>
                            </dd>
                            <dd>
                                <span class="l">¥ ${item.price}</span>
                                <span class="r">已售${item.sales}</span>
                            </dd>
                        </dl>`
            })
            $(htmlEl).html(html)
        } else {
            $.ajax({
                type: 'get',
                url: 'http://localhost:3000/dog/getRecommend',
                data: {
                    type,
                    floor
                },
                dataType: 'json',
                success: function(data) {
                    // console.log(data);
                    showResult[type] = data.data
                    var html = ''
                    if (data.code) {
                        data.data.forEach((item) => {
                            html += `<dl class="first">
                                <dt>
                                        <a href="javascript:;">
                                            <img src="${item.image}" alt="">
                                        </a>
                                    </dt>
                                <dd>
                                    <a href="javascript:;">${item.title}</a>
                                </dd>
                                <dd>
                                    <span class="l">¥ ${item.price}</span>
                                    <span class="r">已售${item.sales}</span>
                                </dd>
                            </dl>`
                        })
                        $(htmlEl).html(html)
                    }
                }
            })
        }
    })
}

// 狗狗商品推荐
function dogGoodsRecommend() {
    var type = 1,
        floor = 0,
        showResult = {}
    dogInit(type, floor, showResult, '.dogbox2')
    dogGet(type, floor, showResult, '.dogmond2 a', '.dogbox2', 'active1')
}

// 一楼 粮食专区
function dogGrain() {
    var type = 1,
        floor = 1,
        showResult = {}
    dogInit(type, floor, showResult, '.grain')
    dogGet(type, floor, showResult, '.dogGrain li a', '.grain', 'current')
}

// 二楼 医疗保健
function dogMedical() {
    var type = 1,
        floor = 2,
        showResult = {}
    dogInit(type, floor, showResult, '.dgcFloor-sl')
    dogGet(type, floor, showResult, '.dogMedical li a', '.dgcFloor-sl', 'current')
}

// 三楼 生活品质
function dogLife() {
    var type = 1,
        floor = 3,
        showResult = {}
    dogInit(type, floor, showResult, '.glq')
    dogGet(type, floor, showResult, '.dogLife li a', '.glq', 'current')
}

// 四楼 清洁卫生
function dogClean() {
    var type = 1,
        floor = 4,
        showResult = {}
    dogInit(type, floor, showResult, '.wdj')
    dogGet(type, floor, showResult, '.dogClean li a', '.wdj', 'current')
}

slideshow()
dogGoodsRecommend()
dogGrain()
dogMedical()
dogLife()
dogClean()
    // 狗狗商品推荐
    /* function dogGoodsRecommend() {
        var type = 1,
            floor = 0,
            // floor = attr('data-floor')
            showResult = {}
        $.ajax({
            type: 'get',
            url: '/getRecommend',
            data: {
                type,
                floor
            },
            dataType: 'json',
            success: function(data) {
                // console.log(data);
                showResult[type] = data.data
                var html = ''
                if (data.code) {
                    data.data.forEach((item) => {
                        html += `<dl class="first">
                        <dt>
                                <a href="javascript:;">
                                    <img src="${item.image}" alt="">
                                </a>
                            </dt>
                        <dd>
                            <a href="javascript:;">${item.title}</a>
                        </dd>
                        <dd>
                            <span class="l">¥ ${item.price}</span>
                            <span class="r">已售${item.sales}</span>
                        </dd>
                    </dl>`
                    })
                    $('.dogbox2').html(html)
                }
            }
        })
        $('.dogmond2 a').on('mouseover', function() {
            $(this).addClass('active1').siblings().removeClass('active1')
            type = $(this).attr('data-type')
                // console.log(type);
            if (showResult[type]) {
                var html = ''
                showResult[type].forEach((item) => {
                    html += `<dl class="first">
                            <dt>
                                    <a href="javascript:;">
                                        <img src="${item.image}" alt="">
                                    </a>
                                </dt>
                            <dd>
                                <a href="javascript:;">${item.title}</a>
                            </dd>
                            <dd>
                                <span class="l">¥ ${item.price}</span>
                                <span class="r">已售${item.sales}</span>
                            </dd>
                        </dl>`
                })
                $('.dogbox2').html(html)
            } else {
                $.ajax({
                    type: 'get',
                    url: '/getRecommend',
                    data: {
                        type,
                        floor
                    },
                    dataType: 'json',
                    success: function(data) {
                        // console.log(data);
                        showResult[type] = data.data
                        var html = ''
                        if (data.code) {
                            data.data.forEach((item) => {
                                html += `<dl class="first">
                                <dt>
                                        <a href="javascript:;">
                                            <img src="${item.image}" alt="">
                                        </a>
                                    </dt>
                                <dd>
                                    <a href="javascript:;">${item.title}</a>
                                </dd>
                                <dd>
                                    <span class="l">¥ ${item.price}</span>
                                    <span class="r">已售${item.sales}</span>
                                </dd>
                            </dl>`
                            })
                            $('.dogbox2').html(html)
                        }
                    }
                })
            }
        })
    }

    // 一楼 粮食专区
    function dogGrain() {
        var type = 1,
            floor = 1,
            showResult = {}
        $.ajax({
            type: 'get',
            url: '/getRecommend',
            data: {
                type,
                floor
            },
            dataType: 'json',
            success: function(data) {
                // console.log(data);
                showResult[type] = data.data
                var html = ''
                if (data.code) {
                    data.data.forEach((item) => {
                        html += `<dl class="first">
                        <dt>
                                <a href="javascript:;">
                                    <img src="${item.image}" alt="">
                                </a>
                            </dt>
                        <dd>
                            <a href="javascript:;">${item.title}</a>
                        </dd>
                        <dd>
                            <span class="l">¥ ${item.price}</span>
                            <span class="r">已售${item.sales}</span>
                        </dd>
                    </dl>`
                    })
                    $('.grain').html(html)
                }
            }
        })
        $('.dogGrain li a').on('mouseover', function() {
            $(this).addClass('current').parent().siblings().children().removeClass('current')
            type = $(this).attr('data-type')
                // console.log(type);
            if (showResult[type]) {
                var html = ''
                showResult[type].forEach((item) => {
                    html += `<dl class="first">
                            <dt>
                                    <a href="javascript:;">
                                        <img src="${item.image}" alt="">
                                    </a>
                                </dt>
                            <dd>
                                <a href="javascript:;">${item.title}</a>
                            </dd>
                            <dd>
                                <span class="l">¥ ${item.price}</span>
                                <span class="r">已售${item.sales}</span>
                            </dd>
                        </dl>`
                })
                $('.grain').html(html)
            } else {
                $.ajax({
                    type: 'get',
                    url: '/getRecommend',
                    data: {
                        type,
                        floor
                    },
                    dataType: 'json',
                    success: function(data) {
                        // console.log(data);
                        showResult[type] = data.data
                        var html = ''
                        if (data.code) {
                            data.data.forEach((item) => {
                                html += `<dl class="first">
                                <dt>
                                        <a href="javascript:;">
                                            <img src="${item.image}" alt="">
                                        </a>
                                    </dt>
                                <dd>
                                    <a href="javascript:;">${item.title}</a>
                                </dd>
                                <dd>
                                    <span class="l">¥ ${item.price}</span>
                                    <span class="r">已售${item.sales}</span>
                                </dd>
                            </dl>`
                            })
                            $('.grain').html(html)
                        }
                    }
                })
            }
        })
    }

    // 二楼 医疗保健
    function dogMedical() {
        var type = 1,
            floor = 2,
            showResult = {}
        $.ajax({
            type: 'get',
            url: '/getRecommend',
            data: {
                type,
                floor
            },
            dataType: 'json',
            success: function(data) {
                // console.log(data);
                showResult[type] = data.data
                var html = ''
                if (data.code) {
                    data.data.forEach((item) => {
                        html += `<dl class="first">
                        <dt>
                                <a href="javascript:;">
                                    <img src="${item.image}" alt="">
                                </a>
                            </dt>
                        <dd>
                            <a href="javascript:;">${item.title}</a>
                        </dd>
                        <dd>
                            <span class="l">¥ ${item.price}</span>
                            <span class="r">已售${item.sales}</span>
                        </dd>
                    </dl>`
                    })
                    $('.dgcFloor-sl').html(html)
                }
            }
        })
        $('.dogMedical li a').on('mouseover', function() {
            $(this).addClass('current').parent().siblings().children().removeClass('current')
            type = $(this).attr('data-type')
                // console.log(type);
            if (showResult[type]) {
                var html = ''
                showResult[type].forEach((item) => {
                    html += `<dl class="first">
                            <dt>
                                    <a href="javascript:;">
                                        <img src="${item.image}" alt="">
                                    </a>
                                </dt>
                            <dd>
                                <a href="javascript:;">${item.title}</a>
                            </dd>
                            <dd>
                                <span class="l">¥ ${item.price}</span>
                                <span class="r">已售${item.sales}</span>
                            </dd>
                        </dl>`
                })
                $('.dgcFloor-sl').html(html)
            } else {
                $.ajax({
                    type: 'get',
                    url: '/getRecommend',
                    data: {
                        type,
                        floor
                    },
                    dataType: 'json',
                    success: function(data) {
                        // console.log(data);
                        showResult[type] = data.data
                        var html = ''
                        if (data.code) {
                            data.data.forEach((item) => {
                                html += `<dl class="first">
                                <dt>
                                        <a href="javascript:;">
                                            <img src="${item.image}" alt="">
                                        </a>
                                    </dt>
                                <dd>
                                    <a href="javascript:;">${item.title}</a>
                                </dd>
                                <dd>
                                    <span class="l">¥ ${item.price}</span>
                                    <span class="r">已售${item.sales}</span>
                                </dd>
                            </dl>`
                            })
                            $('.dgcFloor-sl').html(html)
                        }
                    }
                })
            }
        })
    }

    // 三楼 生活品质
    function dogLife() {
        var type = 1,
            floor = 3,
            showResult = {}
        $.ajax({
            type: 'get',
            url: '/getRecommend',
            data: {
                type,
                floor
            },
            dataType: 'json',
            success: function(data) {
                // console.log(data);
                showResult[type] = data.data
                var html = ''
                if (data.code) {
                    data.data.forEach((item) => {
                        html += `<dl class="first">
                        <dt>
                                <a href="javascript:;">
                                    <img src="${item.image}" alt="">
                                </a>
                            </dt>
                        <dd>
                            <a href="javascript:;">${item.title}</a>
                        </dd>
                        <dd>
                            <span class="l">¥ ${item.price}</span>
                            <span class="r">已售${item.sales}</span>
                        </dd>
                    </dl>`
                    })
                    $('.glq').html(html)
                }
            }
        })
        $('.dogLife li a').on('mouseover', function() {
            $(this).addClass('current').parent().siblings().children().removeClass('current')
            type = $(this).attr('data-type')
                // console.log(type);
            if (showResult[type]) {
                var html = ''
                showResult[type].forEach((item) => {
                    html += `<dl class="first">
                            <dt>
                                    <a href="javascript:;">
                                        <img src="${item.image}" alt="">
                                    </a>
                                </dt>
                            <dd>
                                <a href="javascript:;">${item.title}</a>
                            </dd>
                            <dd>
                                <span class="l">¥ ${item.price}</span>
                                <span class="r">已售${item.sales}</span>
                            </dd>
                        </dl>`
                })
                $('.glq').html(html)
            } else {
                $.ajax({
                    type: 'get',
                    url: '/getRecommend',
                    data: {
                        type,
                        floor
                    },
                    dataType: 'json',
                    success: function(data) {
                        // console.log(data);
                        showResult[type] = data.data
                        var html = ''
                        if (data.code) {
                            data.data.forEach((item) => {
                                html += `<dl class="first">
                                <dt>
                                        <a href="javascript:;">
                                            <img src="${item.image}" alt="">
                                        </a>
                                    </dt>
                                <dd>
                                    <a href="javascript:;">${item.title}</a>
                                </dd>
                                <dd>
                                    <span class="l">¥ ${item.price}</span>
                                    <span class="r">已售${item.sales}</span>
                                </dd>
                            </dl>`
                            })
                            $('.glq').html(html)
                        }
                    }
                })
            }
        })
    }

    // 四楼 清洁卫生
    function dogClean() {
        var type = 1,
            floor = 4,
            showResult = {}
        $.ajax({
            type: 'get',
            url: '/getRecommend',
            data: {
                type,
                floor
            },
            dataType: 'json',
            success: function(data) {
                // console.log(data);
                showResult[type] = data.data
                var html = ''
                if (data.code) {
                    data.data.forEach((item) => {
                        html += `<dl class="first">
                        <dt>
                                <a href="javascript:;">
                                    <img src="${item.image}" alt="">
                                </a>
                            </dt>
                        <dd>
                            <a href="javascript:;">${item.title}</a>
                        </dd>
                        <dd>
                            <span class="l">¥ ${item.price}</span>
                            <span class="r">已售${item.sales}</span>
                        </dd>
                    </dl>`
                    })
                    $('.wdj').html(html)
                }
            }
        })
        $('.dogClean li a').on('mouseover', function() {
            $(this).addClass('current').parent().siblings().children().removeClass('current')
            type = $(this).attr('data-type')
                // console.log(type);
            if (showResult[type]) {
                var html = ''
                showResult[type].forEach((item) => {
                    html += `<dl class="first">
                            <dt>
                                    <a href="javascript:;">
                                        <img src="${item.image}" alt="">
                                    </a>
                                </dt>
                            <dd>
                                <a href="javascript:;">${item.title}</a>
                            </dd>
                            <dd>
                                <span class="l">¥ ${item.price}</span>
                                <span class="r">已售${item.sales}</span>
                            </dd>
                        </dl>`
                })
                $('.wdj').html(html)
            } else {
                $.ajax({
                    type: 'get',
                    url: '/getRecommend',
                    data: {
                        type,
                        floor
                    },
                    dataType: 'json',
                    success: function(data) {
                        // console.log(data);
                        showResult[type] = data.data
                        var html = ''
                        if (data.code) {
                            data.data.forEach((item) => {
                                html += `<dl class="first">
                                <dt>
                                        <a href="javascript:;">
                                            <img src="${item.image}" alt="">
                                        </a>
                                    </dt>
                                <dd>
                                    <a href="javascript:;">${item.title}</a>
                                </dd>
                                <dd>
                                    <span class="l">¥ ${item.price}</span>
                                    <span class="r">已售${item.sales}</span>
                                </dd>
                            </dl>`
                            })
                            $('.wdj').html(html)
                        }
                    }
                })
            }
        })
    }

    slideshow()
    dogGoodsRecommend()
    dogGrain()
    dogMedical()
    dogLife()
    dogClean() */